package com.solocredit.finance.ui.steps.adapter

import android.graphics.Color
import android.view.View
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.solocredit.finance.R
import com.solocredit.finance.base.adapter.MullaRecyclerViewAdapter
import com.solocredit.finance.base.adapter.MullaViewHolderHelper
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/30 10:43
 * @Annotation：流程 - Ocr 适配器
 */
class MullaStepOcrTypeAdapter(recyclerView: RecyclerView?) : MullaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_mulla_step_ocr_type) {

    override fun setItemChildListener(helper: MullaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout)
    }

    override fun fillData(helper: MullaViewHolderHelper, position: Int, model: JSONObject) {
        val itemLayout = helper.getView<RelativeLayout>(R.id.itemLayout)
        val imgOcrType = helper.getImageView(R.id.imgOcrType)
        val textOcrType = helper.getTextView(R.id.textOcrType)
        textOcrType.text = model.optString("ocrTitle")

        val isSelect = model.optBoolean("isSelect",false)
        when (isSelect){
            true -> {
                itemLayout.setBackgroundResource(R.drawable.mulla_radius_frame_ffd21034_12_w2)
                imgOcrType.setImageResource(model.optInt("imgSelect"))
                textOcrType.setTextColor(Color.parseColor("#FF160807"))
                helper.setVisibility(R.id.imgSelected, View.VISIBLE)
            }
            else -> {
                itemLayout.setBackgroundResource(R.drawable.mulla_radius_fill_white_12)
                imgOcrType.setImageResource(model.optInt("imgNormal"))
                textOcrType.setTextColor(Color.parseColor("#FFE0DBEE"))
                helper.setVisibility(R.id.imgSelected, View.GONE)
            }
        }
    }
}